#include "FlowManager.h"
#include <string.h>

int main(int argc, char *argv[])
{
    int ret = 0;
    char data[1024] = { 0 };
    int post = -1;
    // 创建flow id, 第一次读buffer，post为-1
    int flow_id = CreateBufferFlowId(1024, 32);

    // 写入数据两次
    char* usr_data1 = (char*)"this is test data1";
    char* usr_data2 = (char*)"this is test data2";
    WriteDataToBufferFlow(flow_id, usr_data1, strlen(usr_data1) + 1);
    WriteDataToBufferFlow(flow_id, usr_data2, strlen(usr_data2) + 1);

    // 读取数据两次
    ret = ReadDataFromBufferFlow(flow_id, data, 1024, &post);
    printf("read1 ret = %d, data:%s,  post = %d\n", ret, data, post);
    ret = ReadDataFromBufferFlow(flow_id, data, 1024, &post);
    printf("read2 ret = %d, data:%s,  post = %d\n", ret, data, post);

    // 第三次读取，无数据
    ret = ReadDataFromBufferFlow(flow_id, data, 1024, &post);
    printf("read3: ret = %d, post = %d\n", ret, post);

    // 删除flow id
    FreeBufferFlowId(flow_id);

    return 0;
}